//
//  HMSearchView.swift
//  WeiBo
//
//  Created by Apple on 16/9/18.
//  Copyright © 2016年 KY. All rights reserved.
//

import UIKit

class HMSearchView: UIView {
    //  搜索按钮的右边约束
    @IBOutlet weak var SearchTextFieldRightContaints: NSLayoutConstraint!
    @IBOutlet weak var searchButton: UIButton!
    
    @IBOutlet weak var searchTextField: UITextField!

    @IBAction func searchButtonAction(_ sender: AnyObject) {
        
        //  取消第一响应者
        searchTextField.resignFirstResponder()
        
       
        self.SearchTextFieldRightContaints.constant = 0
        //  执行约束动画
        UIView.animate(withDuration: 0.4) {
            
            self.layoutIfNeeded()
        }
    }
    
    
    @IBAction func beginEditAction(_ sender: AnyObject) {
        
        //  开始编辑
        
        self.SearchTextFieldRightContaints.constant = self.searchButton.width
        //  执行约束动画
        UIView.animate(withDuration: 0.4) {
            
            self.layoutIfNeeded()
        }
        
    }
    //  提供类方法使用xib创建对象
    //  类方法以class打头
    class func sharedSearchView() -> HMSearchView {
        
        return UINib(nibName: "HMSearchView", bundle: nil).instantiate(withOwner: nil, options: nil).last! as! HMSearchView
    }
    
    
    
//    override func awakeFromNib() {
//        searchTextField.layer.borderColor = UIColor.red.cgColor
//        searchTextField.layer.borderWidth = 3
//        searchTextField.layer.cornerRadius = 5
//        searchTextField.layer.masksToBounds = true
//    }
    
    
    
    
    
    
    
    
    
    
}
